#pragma once

#include <vector>
#include <cstdint>
#include <cstddef>
#include <string>
#include "pcap.hpp"
#include "mdqp.hpp"

class MDQPParser
{
private:
    std::vector<uint8_t> m_content;
    PcapPaser pcap_parser;
    MDQPHeader *m_mdqp_header;

private:
    void put(uint8_t *data, size_t data_len)
    {
        m_content.insert(m_content.end(), data, data + data_len);
    }
    void parseMDQP();

public:
    MDQPParser(std::string pcap_path) : pcap_parser(pcap_path) {}

    virtual ~MDQPParser()
    {
    }

    bool parse();

    MDQPHeader *getMDQP()
    {
        auto ret = m_mdqp_header;
        void *data_end = m_content.data() + m_content.size();

        if (ret && ret < data_end)
        {
            m_mdqp_header = (MDQPHeader *)((uint8_t *)m_mdqp_header + m_mdqp_header->length + sizeof(MDQPHeader));
        }
        else
        {
            ret = nullptr;
        }
        return ret;
    }
};